package com.java110.mall.shop.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.shop.ShopCommunityDto;
import com.java110.intf.shop.IShopCommunityInnerServiceSMO;
import com.java110.po.shop.ShopCommunityPo;
import com.java110.mall.shop.dao.IShopCommunityServiceDao;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 商铺小区内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class ShopCommunityInnerServiceSMOImpl extends BaseServiceSMO implements IShopCommunityInnerServiceSMO {

    @Autowired
    private IShopCommunityServiceDao shopCommunityServiceDaoImpl;


    @Override
    public int saveShopCommunity(@RequestBody ShopCommunityPo shopCommunityPo) {
        int saveFlag = 1;
        shopCommunityServiceDaoImpl.saveShopCommunityInfo(BeanConvertUtil.beanCovertMap(shopCommunityPo));
        return saveFlag;
    }

    @Override
    public int updateShopCommunity(@RequestBody ShopCommunityPo shopCommunityPo) {
        int saveFlag = 1;
        shopCommunityServiceDaoImpl.updateShopCommunityInfo(BeanConvertUtil.beanCovertMap(shopCommunityPo));
        return saveFlag;
    }

    @Override
    public int deleteShopCommunity(@RequestBody ShopCommunityPo shopCommunityPo) {
        int saveFlag = 1;
        shopCommunityPo.setStatusCd("1");
        shopCommunityServiceDaoImpl.updateShopCommunityInfo(BeanConvertUtil.beanCovertMap(shopCommunityPo));
        return saveFlag;
    }

    @Override
    public List<ShopCommunityDto> queryShopCommunitys(@RequestBody ShopCommunityDto shopCommunityDto) {

        //校验是否传了 分页信息

        int page = shopCommunityDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            shopCommunityDto.setPage((page - 1) * shopCommunityDto.getRow());
        }

        List<ShopCommunityDto> shopCommunitys = BeanConvertUtil.covertBeanList(shopCommunityServiceDaoImpl.getShopCommunityInfo(BeanConvertUtil.beanCovertMap(shopCommunityDto)), ShopCommunityDto.class);

        return shopCommunitys;
    }


    @Override
    public int queryShopCommunitysCount(@RequestBody ShopCommunityDto shopCommunityDto) {
        return shopCommunityServiceDaoImpl.queryShopCommunitysCount(BeanConvertUtil.beanCovertMap(shopCommunityDto));
    }

    public IShopCommunityServiceDao getShopCommunityServiceDaoImpl() {
        return shopCommunityServiceDaoImpl;
    }

    public void setShopCommunityServiceDaoImpl(IShopCommunityServiceDao shopCommunityServiceDaoImpl) {
        this.shopCommunityServiceDaoImpl = shopCommunityServiceDaoImpl;
    }
}
